<!--
  - Copyright(c)  2022 厦门外里科技有限公司 All rights reserved.
  -
  - https://www.wailikeji.com
  -
  - 版权所有，侵权必究！
  -->

<template>
	<view class="panel">
		<view class="panel-content">
			<view class="wrap">
				<u-form class="form" :model="model" :rules="rules" ref="uForm">
					<u-form-item label="昵称" prop="nickName" label-width="180">
						<u-input v-model="model.nickName" placeholder="请输入昵称"></u-input>
					</u-form-item>
					<u-form-item label="头像" prop="wxUrl" label-width="180">
						<u-upload :action="action" max-count="1" :multiple="false" :header="tokenObj"
							@on-success="wxUrlUploadSuccess"></u-upload>
					</u-form-item>
					<u-form-item label="二维码" prop="qrcode" label-width="180">
						<u-upload :action="action" max-count="1" :multiple="false" :header="tokenObj"
							@on-success="qrcodeUploadSuccess"></u-upload>
					</u-form-item>
					<u-form-item label="性别" prop="sex" label-width="180">
						<u-radio-group v-model="model.sex">
							<u-radio :name="-1">不公开</u-radio>
							<u-radio :name="1">男</u-radio>
							<u-radio :name="0">女</u-radio>
						</u-radio-group>
					</u-form-item>
					<u-form-item label="地区" prop="region" label-width="180">
						<u-cell-item :value="model.region" @click="area=true"></u-cell-item>
						<city-select v-model="area" @city-change="cityChange"></city-select>
					</u-form-item>
					<u-form-item label="描述" prop="summary">
						<u-input type="textarea" placeholder="请填写描述" v-model="model.summary" height="200"
							maxlength="500" />
					</u-form-item>
				</u-form>
				<view class="form-footer">
					<u-button class="btn" type="primary" @click="submit">提交</u-button>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		API_URL
	} from '@/env'
	import citySelect from '@/components/my/u-city-select.vue';
	import store from '@/common/store/index.js'
	let _this;
	export default {
		components: {
			citySelect
		},
		data() {
			return {
				model: {
					nickName: '',
					wxUrl: '',
					qrcode: '',
					sex: 1,
					region: '点击选择区域',
					regionValue: ''
				},
				area: false,
				action: API_URL + "/common/oss/uploadPersonal",
				tokenObj: {
					"token": store.state.user.tokenInfo
				}
			};
		},
		mounted() {
			_this = this;
		},
		computed: {
			rules() {
				return {
					nickName: [{
						required: true,
						message: '请输入群名称',
						trigger: ['change', 'blur'],
					}],
					wxUrl: [{
						required: true,
						message: '请上传群头像',
						trigger: ['change', 'blur'],
					}],
					qrcode: [{
						required: true,
						message: '请上传群二维码',
						trigger: ['change', 'blur'],
					}],
					// sex: [{
					// 	required: false,
					// 	message: '请选择性别',
					// 	trigger: ['change', 'blur'],
					// }],
					regionValue: [{
						required: true,
						message: '请选择区域',
						trigger: ['change', 'blur'],
					}]
				}
			}
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			cityChange(e) {
				this.model.region = e.province.label + '-' + e.city.label + '-' + e.area.label;
				this.model.regionValue = e.area.value;
				console.log( e.province.label)
				console.log( e.province.value)
			},
			wxUrlUploadSuccess(res, index, lists, name) {
				console.log("res=",res)
				// this.model.wxUrl = res.fileName
				this.model.wxUrl = res.data.url
			},
			qrcodeUploadSuccess(res, index, lists, name) {
				// this.model.qrcode = res.fileName
				this.model.qrcode = res.data.url
			},
			submit() {
				this.$refs.uForm.validate(valid => {
					if (!valid) {
						this.$u.toast('您填写的信息有误，请根据提示修正。');
						return
					}
					this.$api.api('personalCard.add', this.model)
						.then(res => {
							if (res.code == 200) {
								uni.showToast({
									icon: 'none',
									position: 'bottom',
									title: '发布成功！'
								});
							} else {
								uni.showToast({
									icon: 'none',
									position: 'bottom',
									title: res.msg
								});
							}
						})
				});
			},
		}
	};
</script>
<style lang="scss">
	@import '../../components/my/aidex.scss';

	page {
		background: #f5f5f5;
	}

	.u-form {
		background: #fff;
		padding: 0px 15px;
	}

	.remind-text {
		padding: 20rpx 30rpx;
		color: #666666;
	}


	.panel {
		padding: 0 30upx 0;
		// color: black;

		.panel-content {
			background: white;
			margin: 0 auto;
			border-radius: 16upx; //面包圆形倒角
			box-shadow: 0 2upx 20upx rgba(183, 183, 183, 0.3); //周边阴影
			margin-top: 16upx; //顶部间隔
		}
	}
</style>
